package day8;

import java.util.Scanner;

public interface InterfaceA {
    int method(int n);
}

class ClassA implements InterfaceA{
    @Override
    public int method(int n) {
        int sum=0;
        for (int i=1;i<=n;i++) {
           sum+=i;
        }
        return sum;
    }
}
class ClassB implements InterfaceA{
    @Override
    public int method(int n) {
        int sum=1;
        for (int i=1;i<=n;i++){
            if (n==1){
                sum=1;
            }
            sum*=i;
        }
        return sum;
    }
}

class Test3{
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        System.out.print("请输入一个正整数：");
        int num=sc.nextInt();
        InterfaceA a=new ClassA();
        InterfaceA b=new ClassB();
        System.out.println("1到"+num+"的和为："+a.method(num));
        System.out.println("1到"+num+"的阶乘为："+b.method(num));
    }
}